var requestMethod = [{
		id:'0',
		name:'GET'
	},{
		id:'4',
		name:'POST'
	}];

var urlParamObj;
//定位显示
var arrayLi = [];
var arrayLiInd = 0;
$(document).ready(function() {
		/* 系统树 */
		$('#system_selection').window({
			width:310,
			height:355,
			modal:true,
			minimizable:false,
			maximizable:false,
			collapsible:false,
			onClose: function () {
				$("#tt").html("");
			}
		});
		$('#system_selection').window('close');  //关闭窗口
	
		urlParamObj = getParamobjFromUrl();
		if(urlParamObj.bundleModel == "true"){
			//代理模式
			$("#li_bundleName").css("display","none");
			$(".li_bundle").css("display","none");
			$(".li_depPackage").css("display","none");
			$("#interfaceAddress").css("display","block");
			$("#interfaceOriginAddress").val(urlParamObj.restAddress);
    	}else{
    		//自定义模式
    		$("#li_bundleName").css("display","block");
    		$(".li_bundle").css("display","block");
    		$(".li_depPackage").css("display","block");
    		$("#interfaceAddress").css("display","none");
    	}
		
		// Initialize Smart Wizard
  		$('#wizard').smartWizard({
  		  // Properties
  		    selected: 0,  // Selected Step, 0 = first step   
  		    keyNavigation: true, // Enable/Disable key navigation(left and right keys are used if enabled)
  		    enableAllSteps: false,  // Enable/Disable all steps on first load
  		    transitionEffect: 'fade', // Effect on navigation, none/fade/slide/slideleft
  		    contentURL:null, // specifying content url enables ajax content loading
  		    contentCache:true, // cache step contents, if false content is fetched always from ajax url
  		    cycleSteps: false, // cycle step navigation
  		    enableFinishButton: false, // makes finish button enabled always
  		    errorSteps:[],    // array of step numbers to highlighting as error steps
  		    labelNext:'下一步', // label for Next button
  		    labelPrevious:'上一步', // label for Previous button
  		    labelFinish:'提交',  // label for Finish button        
  		  // Events
  		    onLeaveStep: onLeaveStepCallBack, // triggers when leaving a step
  		    onShowStep: onShowStepCallBack,  // triggers when showing a step
  		    onFinish: onFinishCallBack  // triggers when Finish button is clicked
  		 });
  		
  		 
  		$('#comboxFieldName').combobox({
			url: BASE_URL_FIELD_SEARCH + '/findAllOfCurrentUserCanManage' + '?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    editable:false,
		    method:'get',
		    loadFilter: function(data){
		    	return data.content;
		    },
		    onLoadSuccess:function(){
		    	var FieldName = $('#comboxFieldName').combobox('getData');
		    	$("#comboxFieldName").combobox('setValue',FieldName[0].id);
		    },	
		    onSelect: function(record){
		    	comboxSystemName.combobox({
                    disabled: false,
                    method:'get',
                    queryParams: {fieldId: record.id},
                    url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findByFieldOfCurrentUserCanManage' + '?v=' + Math.random(),
                    valueField: 'id',
                    textField: 'name',
        		    loadFilter: function(data){
        		    	return data.content;
        		    }
                }).load();
		    },
		    onChange: function(newValue,oldValue){
		    	comboxSystemName.combobox({
                    disabled: false,
                    method:'get',
                    queryParams: {fieldId: newValue},
                    url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findByFieldOfCurrentUserCanManage' + '?v=' + Math.random(),
                    valueField: 'id',
                    textField: 'name',
        		    loadFilter: function(data){
        		    	return data.content;
        		    },
        		    onLoadSuccess : function(){
        		    	var SystemName = $('#comboxSystemName').combobox('getData');
        				$("#comboxSystemName").combobox('setValue',SystemName[0].id);
        		    }
                }).load();
		    }
		    
		});
		
		
		var comboxSystemName = $('#comboxSystemName').combobox({
            disabled: true,
            valueField: 'id',
            textField: 'name',
            editable:false
        });
		
		$('#comboxInterfaceDataFormat').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_INTERFACE_DATA_FORMAT + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter:function(data){
		    	return data;
		    },
		    onLoadSuccess:function(){
		    	$("#comboxInterfaceDataFormat").combobox('setValue',"2");
		    }
		});
		
		
		var comboxInterfaceReqeustMethod = $('#comboxInterfaceReqeustMethod').combobox({
            valueField: 'id',
            textField: 'name',
            editable: false,
		  	data:requestMethod,
		  	onLoadSuccess:function(){
		    	$("#comboxInterfaceReqeustMethod").combobox('setValue',"0");
		    }
        });
		
		$('#comboxReqParameterType').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_PARAMETER_TYPE + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter:function(data){
		    	return data;
		    },
		    onLoadSuccess:function(){
		    	var reqParameterType = $('#comboxReqParameterType').combobox('getData');
		    	$("#comboxReqParameterType").combobox('setValue',reqParameterType[0].valueCode);
		    }
		});
		
		
		$('#reviseComboxReqParameterType').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_PARAMETER_TYPE + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter:function(data){
		    	return data;
		    },
		    onLoadSuccess:function(){
		    	var reqParameterType = $('#reviseComboxReqParameterType').combobox('getData');
		    	$("#reviseComboxReqParameterType").combobox('setValue',reqParameterType[0].valueCode);
		    }
		});
		
		$('#reviseComboxRepParameterType').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_PARAMETER_TYPE + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter:function(data){
		    	return data;
		    },
		    onLoadSuccess:function(){
		    	var reqParameterType = $('#reviseComboxRepParameterType').combobox('getData');
		    	$("#reviseComboxRepParameterType").combobox('setValue',reqParameterType[0].valueCode);
		    }
		});
		
		$('#comboxRepParameterType').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_PARAMETER_TYPE + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter:function(data){
		    	return data;
		    },
		    onLoadSuccess:function(){
		    	var repParameterType = $('#comboxRepParameterType').combobox('getData');
		    	$("#comboxRepParameterType").combobox('setValue',repParameterType[0].valueCode);
		    }
		});
		
		
		
		
		$('#comboxIsPublic').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_IS_PUBLIC + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter:function(data){
		    	return data;
		    },
		    onLoadSuccess:function(){
		    	var isPublic = $('#comboxIsPublic').combobox('getData');
		    	$("#comboxIsPublic").combobox('setValue',isPublic[0].valueCode);
		    	
		    	var chooseVal = $("#comboxIsPublic").combobox('getValue');
		    	if(chooseVal=="0"){
		    		$("#li_visible").css("display","block");
		    	}else{
		    		$("#li_visible").css("display","none");
		    	}
		    	
		    },
		    onSelect: function(record){
		    	var chooseVal = $("#comboxIsPublic").combobox('getValue');
		    	if(chooseVal=="0"){
		    		$("#li_visible").css("display","block");
		    	}else{
		    		$("#li_visible").css("display","none");
		    	}
		    }
		});
		
		
		$('#comboxOperationType').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_OPERATION_TYPE + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter:function(data){
		    	return data;
		    },
		    onLoadSuccess:function(){
		    	var operationType = $('#comboxOperationType').combobox('getData');
		    	$("#comboxOperationType").combobox('setValue',operationType[0].valueCode);
		    }
		});
		
		$('#comboxAuthencationMode').combobox({
			url: BASE_URL_DATA_DICTIONARY_VALUE_SEARCH +'/findByTypeCode?typeCode='+DDTC_AUTHENTICATION_MODE + '&v=' + Math.random(),
			valueField: 'valueCode',
		    textField: 'valueName',
		    editable:false,
		    method:'get',
		    loadFilter:function(data){
		    	for(var i=0; i<data.length; i++)  
		        {  
		            var curObj = data[i];  
		            if(curObj.valueCode === "3")  
		            {  
		            	data.splice(i,1);  
		            }  
		        }
		    	return data;
		    },
		    onLoadSuccess:function(){
		    	var authencationMode = $('#comboxAuthencationMode').combobox('getData');
		    	$("#comboxAuthencationMode").combobox('setValue',authencationMode[0].valueCode);
		    }
		});
		
		
		
		  
	  	function onLeaveStepCallBack(obj, context){
	  		var step_num= obj.attr('rel'); // get the current step number
	  		/*验证表单数据是否正确*/
	  		
	  		/*保存表单数据*/
	  		if(context.fromStep < context.toStep){
		  		if(step_num == 1){
		  			if(!$("#basicInfoForm").form("validate")){
		  				return false;
		  			}
		  			if(urlParamObj.bundleModel == "true"){
						//代理模式
		  				var interfaceOriginAddress = $.trim($("#interfaceOriginAddress").val());
		  				if(interfaceOriginAddress != "")
						{
						}else
						{
							$.messager.alert('警告', '<p>接口原始地址不能为空!</p>', 'warning');
							return false;
						}
					}else{
						//自定义模式
						var packageJarNames = $.trim($("#packageJarName").val());
						if(packageJarNames != "")
						{
						}else
						{
							$.messager.alert('警告', '<p>接口部署包不能为空!</p>', 'warning');
							return false;
						}
					}
		  		}else if(step_num == 2){
		  		}else if(step_num == 3){
		  			
		  		}else if(step_num == 4){
		  			if(!$("#limitForm").form("validate")){
		  				return false;
		  			}
		  		}else{
		  			
		  		}
	  		}
	  		
	  		return true;
	  	}
	  	
	  	function onShowStepCallBack(obj){
	  		var step_num= obj.attr('rel');
	  		if(step_num == 1){
	  			//alert("onShowStepCallBack" + step_num);
	  		}else if(step_num == 2){
	  			//alert("onShowStepCallBack" + step_num);
	  		}else if(step_num == 3){
	  			//alert("onShowStepCallBack" + step_num);
	  		}else{
	  			//alert("onShowStepCallBack" + step_num);
	  		}
	  		
	  	}
	  	
	  	function onFinishCallBack(){
	  		var result = getFormDatas();
	  		if(result == false){
	  			return;
	  		}
	  		var interfaceDatas = getFormDatas();
	  		var jsonData = {
				  	interfaceDatas:interfaceDatas
				};
	  		
	  		//alert(JSON.stringify(jsonData));
	  		if($("#basicInfoForm").form("validate") && $("#limitForm").form("validate")){
	  			$("#progressbar, #progressbar_tips").fadeIn();
	  			loading_point.timer = setInterval(loading,200);
		  		$.ajax({
		  			type: "post",
		  			url: BASE_URL_HTTP_INTERFACE + '/httpServiceRegister' + '?v=' + Math.random(),
		  			dataType:'json',
		  			data: JSON.stringify(jsonData),
		  			contentType:"application/json",
		  			success: function(result) {
		  				$("#progressbar, #progressbar_tips").fadeOut();
						clearInterval(loading_point.timer);
		  				if(result.backValue == true){
		  					$.messager.alert('提示','<p>注册成功</p>','info',function(){
		  						window.parent.OpenTab("业务服务管理","pages/esb/ServiceManagement/businessServiceManagement.html","", true);
		  					});
		  				}else if(result.backValue == false){
		  					$.messager.alert('错误','<p>' + result.errorDes + '</p>','error');
		  				}else{
		  					
		  				}
		  			},
		  			error: function() {
		  				$("#progressbar, #progressbar_tips").fadeOut();
						clearInterval(loading_point.timer);
		  				$.messager.alert('错误','<p>服务异常，注册失败，请稍后重试或联系管理员!</p>', 'error');
		  			}
		  		});
	  		};
	  		
	  	}
		
	  	
	    //动态添加接口请求参数数据项
		$(".confirm_title").click(function(e) {
			if($("#requestParametersForm").form("validate")){
	            var reqParameterName = $("#reqParameterName").val();
				var reqParameterType = $("#comboxReqParameterType").combobox('getValue');
				var reqParameterTypeDispaly = $("#comboxReqParameterType").combobox('getText');
				var reqParameterIsMust = $("#reqParameterIsMust").is(":checked");
				var reqParameterIsMustValue;
				//alert($("#reqParameterIsMust").is(":checked"));
				
				var reqParameterIsMustDispaly;
				if(reqParameterIsMust == true){
					reqParameterIsMustValue = "1";
					reqParameterIsMustDispaly = "是";
				}else{
					reqParameterIsMustValue = "0";
					reqParameterIsMustDispaly = "否";
				}
				var reqParameterDefaultValue = $("#reqParameterDefaultValue").val();
				var reqParameterDes = $("#reqParameterDes").val();
				if(reqParameterName != '' && reqParameterType !== '')
				{
					var tableHtml = '<tr id="rev_index' + Math.floor(Math.random()*100000) + '"><td width="16.7%" class="reqParameterName"><p class="txtP" title="' + reqParameterName + '">' + reqParameterName + '</p></td><td width="16.7%" class="comboxReqParameterType" data-val="' + reqParameterType + '"><p class="txtP" title="' + reqParameterTypeDispaly + '">' + reqParameterTypeDispaly + '</p></td><td width="16.7%" class="reqParameterIsMust" data-val="' + reqParameterIsMustValue + '"><p class="txtP" title="' + reqParameterIsMustDispaly + '">' + reqParameterIsMustDispaly + '</p></td><td width="16.7%" class="reqParameterDefaultValue"><p class="txtP" title="' + reqParameterDefaultValue + '">' + reqParameterDefaultValue + '</p></td><td width="16.7%" class="reqParameterDes"><p class="txtP" title="' + reqParameterDes + '">' + reqParameterDes + '</p></td><td width="16.7%" class="operation_table"><a href="javascript:void(0);" class="change_title">更改</a><a href="javascript:void(0);" class="del_title">删除</a></td></tr>';
					$(".add").find("tr").eq(0).after(tableHtml);
					$("#reqParameterName, #comboxReqParameterType, #reqParameterIsMust, #reqParameterDefaultValue, #reqParameterDes").val('');
				}else
				{
					$.messager.alert('警告', '<p>请填写完整！</p>', 'warning');
				}
			}
			else
			{
				$(".interfaceDataAdd .validatebox-invalid").eq(0).focus();
			}
        });
	  
	  
		//修改接口请求参数数据项
		$('#interface_change').window({
			width:650,
			height:140,
			modal:true,
			minimizable:false,
			maximizable:false,
			collapsible:false
		});
		$('#interface_change').window('close');  //关闭窗口
		var rev_index;
		$("body").delegate(".change_title","click",function(e) {
			$("#reviseReqParameterName, #reviseComboxReqParameterType, #reviseReqParameterIsMust, #reviseReqParameterDefaultValue, #reviseReqParameterDes").val("");
			rev_index = $(this).parents("tr").attr("id");
			var reqParameterName = $(this).parents("td").siblings(".reqParameterName").text();
			var reqParameterType = $(this).parents("td").siblings(".comboxReqParameterType").attr("data-val");
			var reqParameterDes = $(this).parents("td").siblings(".reqParameterDes").text();
			var reqParameterDefaultValue = $(this).parents("td").siblings(".reqParameterDefaultValue").text();
			var reqParameterIsMust = $(this).parents("td").siblings(".reqParameterIsMust").attr("data-val");
			var html;
			
			$("#reviseReqParameterName").val(reqParameterName);
			$("#reviseComboxReqParameterType").combobox('select',reqParameterType);
			if(reqParameterIsMust == "1"){
				$("#reviseReqParameterIsMust")[0].checked = true;
			}else{
				$("#reviseReqParameterIsMust")[0].checked = false;
			}
			$("#reviseReqParameterDefaultValue").val(reqParameterDefaultValue);
			$("#reviseReqParameterDes").val(reqParameterDes);
			$('#interface_change').window('open');	
			return false;
		});
		
		$("body").delegate(".confirm_title_revise","click",function(e) {
			if($("#requestReviseParam").form("validate")){
				$("#" + rev_index).children(".reqParameterName").html('<p class="txtP" title="' + $("#reviseReqParameterName").val() + '">' + $("#reviseReqParameterName").val() + '</p>');
				$("#" + rev_index).children(".comboxReqParameterType").attr("data-val",$("#reviseComboxReqParameterType").combobox('getValue'));
				$("#" + rev_index).children(".comboxReqParameterType").html('<p class="txtP" title="' + $("#reviseComboxReqParameterType").combobox('getText') + '">' + $("#reviseComboxReqParameterType").combobox('getText') + '</p>');
				var reviseReqParameterIsMust = $("#reviseReqParameterIsMust").is(":checked");
				var reviseReqParameterIsMustValue;
				if(reviseReqParameterIsMust == true){
					reviseReqParameterIsMustValue = "1";
					reviseReqParameterIsMustDispaly = "是";
				}else{
					reviseReqParameterIsMustValue = "0";
					reviseReqParameterIsMustDispaly = "否";
				}
				
				$("#" + rev_index).children(".reqParameterIsMust").attr("data-val",reviseReqParameterIsMustValue);
				$("#" + rev_index).children(".reqParameterIsMust").html('<p class="txtP" title="' + reviseReqParameterIsMustDispaly + '">' + reviseReqParameterIsMustDispaly + '</p>');
				$("#" + rev_index).children(".reqParameterDefaultValue").html('<p class="txtP" title="' + $("#reviseReqParameterDefaultValue").val() + '">' + $("#reviseReqParameterDefaultValue").val() + '</p>');
				$("#" + rev_index).children(".reqParameterDes").html('<p class="txtP" title="' + $("#reviseReqParameterDes").val() + '">' + $("#reviseReqParameterDes").val() + '</p>');
				$('#interface_change').window('close');		
			}else{
				$(".interfaceDataAdd .validatebox-invalid").eq(0).focus();
			}
		});
		
		//删除接口数据项
		$("body").delegate(".del_title","click",function(){
			$(this).parents("tr").remove();
		});
		
		
		
		 //动态添加接口返回参数数据项
		$(".confirm_title_rep").click(function(e) {
			if($("#responseParametersForm").form("validate")){
	            var repParameterName = $("#repParameterName").val();
				var repParameterType = $("#comboxRepParameterType").combobox('getValue');
				var repParameterTypeDispaly = $("#comboxRepParameterType").combobox('getText');
				var repParameterDes = $("#repParameterDes").val();
				if(repParameterName != '' && repParameterType !== '')
				{
					var tableHtml = '<tr id="rev_index' + Math.floor(Math.random()*100000) + '"><td width="25%" class="repParameterName"><p class="txtPP" title="' + repParameterName + '">' + repParameterName + '</p></td><td width="25%" class="comboxRepParameterType" data-val="' + repParameterType + '"><p class="txtPP" title="' + repParameterTypeDispaly + '">' + repParameterTypeDispaly + '</p></td><td width="25%" class="repParameterDes"><p class="txtPP" title="' + repParameterDes + '">' + repParameterDes + '</p></td><td width="25%" class="operation_table"><a href="javascript:void(0);" class="change_title_rep">更改</a><a style="margin-left:10px;" href="javascript:void(0);" class="del_title_rep">删除</a></td></tr>';
					$(".add_rep").find("tr").eq(0).after(tableHtml);
					$("#repParameterName, #comboxRepParameterType, #repParameterDes").val('');
				}else
				{
					$.messager.alert('警告', '<p>请填写完整！</p>', 'warning');
				}
			}
			else
			{
				$(".interfaceDataAdd_rep .validatebox-invalid").eq(0).focus();
			}
	    });
		
		
		//修改接口返回参数数据项
		$('#interface_change_rep').window({
			width:555,
			height:140,
			modal:true,
			minimizable:false,
			maximizable:false,
			collapsible:false
		});
		$('#interface_change_rep').window('close');  //关闭窗口
		var rev_index;
		$("body").delegate(".change_title_rep","click",function(e) {
			$("#reviseRepParameterName, #reviseComboxRepParameterType, #reviseRepParameterDes").val("");
			rev_index = $(this).parents("tr").attr("id");
			var repParameterName = $(this).parents("td").siblings(".repParameterName").text();
			var repParameterType = $(this).parents("td").siblings(".comboxRepParameterType").attr("data-val");
			var repParameterDes = $(this).parents("td").siblings(".repParameterDes").text();
			var html;
			
			$("#reviseRepParameterName").val(repParameterName);
			$("#reviseComboxRepParameterType").combobox('select',repParameterType);
			$("#reviseRepParameterDes").val(repParameterDes);
			$('#interface_change_rep').window('open');	
			return false;
		});
		
		$("body").delegate(".confirm_title_revise_rep","click",function(e) {
			if($("#reponseReviseParam").form("validate")){
				$("#" + rev_index).children(".repParameterName").html('<p class="txtPP" title="' + $("#reviseRepParameterName").val() + '">' + $("#reviseRepParameterName").val() + '</p>');
				$("#" + rev_index).children(".comboxRepParameterType").attr("data-val",$("#reviseComboxRepParameterType").combobox('getValue'));
				$("#" + rev_index).children(".comboxRepParameterType").html('<p class="txtPP" title="' + $("#reviseComboxRepParameterType").combobox('getText') + '">' + $("#reviseComboxRepParameterType").combobox('getText') + '</p>');
				$("#" + rev_index).children(".repParameterDes").html('<p class="txtPP" title="' + $("#reviseRepParameterDes").val() + '">' + $("#reviseRepParameterDes").val() + '</p>');
				$('#interface_change_rep').window('close');	
			}else{
				$(".interfaceDataAdd .validatebox-invalid").eq(0).focus();
			}
		});
		
		
		//删除接口返回数据项
		$("body").delegate(".del_title_rep","click",function(){
			$(this).parents("tr").remove();
		});
		
		
		/* 可见范围 */
		$("#selSystemBtn").click(function(e) {
			//if(treeData==null){
				$("#tt").tree({
					url:BASE_URL_TREE + '/getFieldSystemsForEasyUiTree' + '?v=' + Math.random(),
					method: "get",
					lines:false,
					async:false,
					checkbox: true,
					loadFilter: function(data,parent) {
						treeData = [{text:"全部", children:data, nodeType:"root"}];
						return treeData;
					},
					onLoadSuccess:function()
					{
						$("#tt > li > ul > li > ul > li > .tree-node > .tree-file").css("background","url('../../../images/st_folder.png') no-repeat 2px 2px");
						$("#tt > li > ul > li > .tree-node > .tree-file").parent().parent().css("display","none");
						reSetTree();
					},
					onClick:function(node){
						if(node.checked)
						{
							$("#tt").tree("uncheck", node.target);
						}
						else
						{
							$("#tt").tree("check", node.target);
						}
						
						//$("#systemName").val(node.text);
						//choose_tree();
					}
				});
			//}else{
				//reSetTree()
			//}
			
			
			return false;
		});
		
		$("#ensureSelect").click(function (e) {
			var checkedNodes = $("#tt").tree("getChecked");
			var selectSystems = "";
			var systemsName = "";
			for(var i = 0, len = checkedNodes.length; i < len; ++i)
			{
				var tempNode = checkedNodes[i];
				if(tempNode.nodeType != "fieldSystem")
				{
					continue;
				}
				selectSystems += (selectSystems != ""? ",":"") + tempNode.id;
				systemsName += (systemsName != ""? ",":"") + tempNode.text;
			}
			$("#strFieldSystems").val(selectSystems);
			$("#system").val(systemsName);
			$('#system_selection').window('close');	
		});
		
		
		$("#searchNode").click(function (e) { 
			if($("#systemName").val() != '')
			{
				choose_tree();
			}
			else
			{
				$(".systemName").val("");
				var row = $('#tt li .tree-node');  
				row.removeClass('tree-node-selected');
				$(".tree_con").scrollTop(0);
			}
		});
		
		$("#systemName").bind('input propertychange', function() {
			arrayLi = [];
			arrayLiInd = 0;
			if($("#systemName").val() != '')
			{
				choose_tree();
			}else
			{
				$("#ff input").val("");
				var row = $('#tt li .tree-node');  
				row.removeClass('tree-node-selected');
				$(".tree_con").scrollTop(0);
			}
		});
		
		$(document , "#systemName").keyup(function(event){
		  if(event.keyCode == 8){
		    $("#searchNode").trigger("click");
		  }
		});
		$(document , "#systemName").keyup(function(event){
		  if(event.keyCode ==13){
		    $("#searchNode").trigger("click");
		  }
		});
		
		/* 可见范围 */
			
  	}); 
  
	//接口请求数据项数据转JSON
	var columnDefinitions;
	function interfaceData()
	{
		var table_con = $(".add tbody").children().clone();
		$(".interfaceData tbody").html('<tr><th width="20%">reqParameterName</th><th width="20%">comboxReqParameterType</th><th width="20%">reqParameterIsMust</th><th width="20%">reqParameterDefaultValue</th><th width="20%">reqParameterDes</th></tr>');
		$(".interfaceData tbody").append(table_con);
		$(".interfaceData tr:eq(1)").remove();
		for(var i = 1, len = $(".interfaceData tr").length; i < len; i++)
		{
			$(".interfaceData tr:eq(" + i + ") td:eq(1)").text($(".interfaceData tr:eq(" + i + ") td:eq(1)").attr("data-val"));
			$(".interfaceData tr:eq(" + i + ") td:eq(2)").text($(".interfaceData tr:eq(" + i + ") td:eq(2)").attr("data-val"));
		}		
		$(".interfaceData tr td:last-child").remove();
		columnDefinitions = $('.interfaceData').tableToJSON(); 
		//alert(JSON.stringify(columnDefinitions));
		return columnDefinitions;
	}
	
	
	//接口返回数据项数据转JSON
	var columnDefinitions_rep;
	function interfaceData_rep()
	{
		var table_con = $(".add_rep tbody").children().clone();
		$(".interfaceData_rep tbody").html('<tr><th width="20%">repParameterName</th><th width="20%">comboxRepParameterType</th><th width="20%">repParameterDes</th></tr>');
		$(".interfaceData_rep tbody").append(table_con);
		$(".interfaceData_rep tr:eq(1)").remove();
		for(var i = 1, len = $(".interfaceData_rep tr").length; i < len; i++)
		{
			$(".interfaceData_rep tr:eq(" + i + ") td:eq(1)").text($(".interfaceData_rep tr:eq(" + i + ") td:eq(1)").attr("data-val"));
		}		
		$(".interfaceData_rep tr td:last-child").remove();
		columnDefinitions_rep = $('.interfaceData_rep').tableToJSON(); 
		return columnDefinitions_rep;
	}
	
	
	//获取所有表单数据
	var interfaceDatas;
	function getFormDatas(){
		
			var interfaceName = $.trim($("#interfaceName").val());
			var interfaceCode = $("#interfaceCode").val();
			var fieldId = $("#comboxFieldName").combobox("getValue");
			var systemId = $("#comboxSystemName").combobox("getValue");
			var interfaceVersion = $.trim($("#interfaceVserion").val());
			var interfaceDataFormat = $("#comboxInterfaceDataFormat").combobox("getValue");
			
			var interfaceRequestMethod = $("#comboxInterfaceReqeustMethod").combobox("getValue");
			
			/*var bundleMode = $("#comboxBundleModel").combobox("getValue");*/
			var bundleMode;
			/*var bundleName;*/
			if(urlParamObj.bundleModel == "true"){
				bundleMode = "0";
			}else{
				/*bundleName = $.trim($("#bundleName").val());*/
				bundleMode = "1";
			}
			var interfaceOriginAddress = $.trim($("#interfaceOriginAddress").val());
			var interfaceDes = $.trim($("#interfaceDescriptions").val());

  			var requestParameterMsg  = $.trim($("#requestParametersMsg").val());
  			/*if(requestParameterMsg != "")
			{
			}else
			{
				$.messager.alert('警告', '<p>请求参数报文不能为空!</p>', 'warning');
				return false;
			}*/
  			var requestParameters  = interfaceData();
  			
  			var responseParametersMsg = $.trim($("#responseParametersMsg").val());
  			/*if(responseParametersMsg != "")
			{
			}else
			{
				$.messager.alert('警告', '<p>返回参数报文不能为空!</p>', 'warning');
				return false;
			}*/
  			var responseParameters = interfaceData_rep();
  			
  			var alarmThreshold = parseInt($.trim($("#alarmThreshold").val()));
  			var alarmMax = parseInt($.trim($("#alarmMax").val()));
  			if(alarmThreshold > alarmMax){
  				$.messager.alert('警告', '<p>请求告警阀值不能大于请求最大值!</p>', 'warning');
				return false;
  			}
  			var overTimeSetting = $.trim($("#overTimeSetting").val());
  			var operationType = $("#comboxOperationType").combobox("getValue");
  			var isPublic = $("#comboxIsPublic").combobox("getValue");
  			var authencationMode = $("#comboxAuthencationMode").combobox("getValue");
  			var transportProtocol = $('input[name="transportProtocol"]:checked ').val();
  			
  			
  			var interfaceType = urlParamObj.serviceType;
				
  			interfaceDatas = {
				interfaceName:interfaceName,
	  			interfaceCode:interfaceCode,
	  			fieldId:fieldId,
	  			systemId:systemId,
	  			interfaceVersion:interfaceVersion,
	  			interfaceDataFormat:interfaceDataFormat,
	  			interfaceRequestMethod:interfaceRequestMethod,
	  			bundleMode:bundleMode,
	  			/*bundleName:bundleName,*/
	  			interfaceOriginAddress:interfaceOriginAddress,
	  			interfaceDes:interfaceDes,
				requestParameterMsg:requestParameterMsg,
				responseParametersMsg:responseParametersMsg,
				alarmThreshold:alarmThreshold,
				alarmMax:alarmMax,
				overTimeSetting:overTimeSetting,
				isPublic:isPublic,
				operationType:operationType,
				transportProtocol:transportProtocol,
				isBundleName:isBundleName,
				authencationMode:authencationMode,
				interfaceType:interfaceType,
				requestParameters:requestParameters,
				responseParameters:responseParameters
			}
  			
  			var fieldSystemsStr = $("#strFieldSystems").val();
  			if(fieldSystemsStr != ""){
	  			if(fieldSystemsStr.indexOf(",") != -1){
	  				interfaceDatas["fieldSystemIds"] = fieldSystemsStr == ""? []:fieldSystemsStr.split(",");
	  			}else{
	  				interfaceDatas["fieldSystemIds"] = [fieldSystemsStr];
	  			}
  			}else{
  				interfaceDatas["fieldSystemIds"] = [];
  			}
  			
  			
  			
  			if(urlParamObj.bundleModel == "true"){
  				
			}else{
				var packageJarNames = $.trim($("#packageJarName").val());
				if(packageJarNames != "")
				{
				}else
				{
					$.messager.alert('警告', '<p>部署包名称不能为空!</p>', 'warning');
					return;
				}
				if(packageJarNames != ""){
					if(packageJarNames.indexOf(",") != -1){
						//alert(packageJarNames);
						interfaceDatas["packageJarNames"] = packageJarNames == ""? []:packageJarNames.split(",");
					}else{
						interfaceDatas["packageJarNames"] = [packageJarNames];
					}
				}else{
					interfaceDatas["packageJarNames"] = [];
				}
				
				var dependsPackagesStr = $("#strdependsPackages").val();
	  			if(dependsPackagesStr != ""){
		  			if(dependsPackagesStr.indexOf(",") != -1){
		  				interfaceDatas["dependsPackageIds"] = dependsPackagesStr == ""? []:dependsPackagesStr.split(",");
		  			}else{
		  				interfaceDatas["dependsPackageIds"] = [dependsPackagesStr];
		  			}
	  			}else{
	  				interfaceDatas["dependsPackageIds"] = [];
	  			}
			}
  			return interfaceDatas;
	}
	
	
	
	function setChecked(sysName) {
		if(!sysName)
		{
			return;
		}
		$("#tt li .tree-node").each(function(){
			if($(".tree-title", $(this)).text() == sysName)
			{
				$('#tt').tree('check', this);
				return false;
			}
		});
		
	}
	
	function setCheckedList(sysNameArr)
	{
		if(sysNameArr && sysNameArr.length)
		{
			for(var i = 0, len = sysNameArr.length; i < len; ++i)
			{
				setChecked(sysNameArr[i]);
			}
		}
	}
	
	function reSetTree(){
		$('#system_selection').window('open');	
		var txtInterface = $("#system").val().split(",")[0];
	
		if(txtInterface !== '')
		{
			$("#systemName").val(txtInterface);
			choose_tree();
		}
		else
		{
			$("#systemName").val('');
			$(".tree_con").scrollTop(0);
			var row = $('#tt li .tree-node');  
			row.removeClass('tree-node-selected');
		}
		
		var checkedNodes = $("#tt").tree("getChecked");
		if(checkedNodes)
		{
			$.each(checkedNodes, function(index, node) {
				$("#tt").tree("uncheck", node.target);
			});
		}
		
		var currSystemsStr = $("#system").val();
		if(currSystemsStr != '')
		{
			setCheckedList(currSystemsStr.split(","));
		}
	}
	
	
	function choose_tree()
	{
		$('#tt').tree('expandAll');
		if(arrayLi.length == 0 && arrayLiInd == 0)
		{
			var searchVal = $("#systemName").val().toUpperCase(); 
			var row = $('#tt li .tree-node');  
			var rowcolumn = $('#tt li .tree-node > .tree-title');  
			var i = 0, j = 0;
			var offsetC = 0
			row.removeClass('tree-node-selected');  
			rowcolumn.each(function (column) {  
				var matchVal = $(this).text(); 
				if(matchVal.indexOf(searchVal) != -1)
				{
					i++;
					var panel_top = parseInt($(this).parents(".panel").css("top"), 10);
					
					if(i <= 1)
					{
						$(this).parent().addClass('tree-node-selected'); 
						var top = $(".tree_con").scrollTop() + $(this).offset().top - 76 - panel_top;
						$(".tree_con").scrollTop(top);
						arrayLiInd = 1;
					}			
					arrayLi.push([matchVal,$(".tree_con").scrollTop() + $(this).offset().top - 76 - panel_top]);
					
				}
				}); 
			}else
			{
				var rowcolumn = $('#tt li .tree-node > .tree-title'); 
				var row = $('#tt li .tree-node');  
				row.removeClass('tree-node-selected');
				
				if(arrayLiInd <  arrayLi.length)
				{
					rowcolumn.each(function (column) {  
						var matchVal = $(this).text(); 
						if(matchVal == arrayLi[arrayLiInd][0])
						{
							$(this).parent().addClass('tree-node-selected'); 
							$(".tree_con").scrollTop(arrayLi[arrayLiInd][1]);
							arrayLiInd++;
							return false;
						}
					});
				}else
				{
					//arrayLi = [];
					arrayLiInd = 0;
					$(".tree_con").scrollTop(0);
					choose_tree();
				}
			}
	}
	
	var loading_point = {
			timer:null,
			len:3,
			count:0
		};
	function loading()
	{
	 	if(loading_point.count < loading_point.len)
		{
			loading_point.count++;
			$("#progressbar_point").text($("#progressbar_point").text() + ".");
		}else
		{
			loading_point.count = 0;
			$("#progressbar_point").text("");
		}	
	}
	
	
	